package cn.springcloud.fix.demo.leecode;

public class Test05 {

    public static void main(String[] args) {
        //System.out.println(0 - '0');
        //reverseString("abcdef");
        //reverseString("abcdefg");
        //convertNumber("1001");
        //convertNumber("-1001");
        move1();
        move2();
        move3();
    }

    private static void move1() {
        int[] R = new int[]{3, 55, 2, 1, 5, 3, 7, 2, 345, 1};
        int len = R.length;
        int p = 3;
        for (int j = 0; j < p; j++) {
            int tmp = R[0];
            System.arraycopy(R, 1, R, 0, len - 1);
            R[len - 1] = tmp;
        }
    }

    private static void move2() {
        int[] R = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        int len = R.length;

        int p = 5;
        int[] R2 = new int[p];
        for (int i = 0; i < p; i++) {
            R2[i] = R[i];
        }

        for (int i = 0; i < len - p; i++) {
            R[i] = R[i + p];
        }

        for (int i = len - p; i < len; i++) {
            R[i] = R2[i - len + p];
        }
    }

    private static void move3() {
        int[] R = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        int len = R.length;

        int p = 5;
        int[] R2 = new int[len];
        for (int i = p; i < len; i++) {
            R2[i - p] = R[i];
        }

        for (int i = 0; i < p; i++) {
            R2[len - p + i] = R[i];
        }

        for (int i = 0; i < len; i++) {
            System.out.println(R2[i]);
        }
    }

    private static void reverseString(String abc) {
        int len = abc.length();
        int middle = len / 2;
        char[] chars = new char[len];
        for (int i = 0; i <= middle; i++) {
            Character tmp = abc.charAt(i);
            chars[i] = abc.charAt(len - 1 - i);
            chars[len - 1 - i] = tmp;
        }
        System.out.println(new String(chars));
    }

    private static void convertNumber(String a) {
        int num = 0;
        boolean flag = a.charAt(0) == '-';
        if (flag) {
            for (int i = 1; i < a.length(); i++) {
                char c = a.charAt(i);
                num = num * 10 - c + 48;
            }
            System.out.println(num);
        } else {
            for (int i = 0; i < a.length(); i++) {
                char c = a.charAt(i);
                num = num * 10 + c - 48;
            }
            System.out.println(num);
        }
    }
}
